<!--
    action弹窗基类
-->
<template>

</template>
<script>
import Modal from '../actionModal';
import $ from '@/common';
export default {
	props: {
		open: {},
		//action模型
		actionModel: {},
		//action当前参数
		actionData: {},
		modalShow: {},
		paramId: {},
		paramData: {},
		isLoad: {
			defalut: false,
		},
	},
	watch: {
		open(v) {
			this.modal = v;
		},
		modal(v) {
			if (v) {
				//基类中保留的处理
				this.baseLoad();
				//用于子类的继承
				this.load();
			}
			this.$emit('update:open', v);
		},
	},
	data() {
		return {
			modal: false,
			title: '弹窗',
			enableSubmit: true,
			submitMethod: 'post',
		};
	},
	computed: {
		modalTitle() {
			if (this.actionModel && this.actionModel.name) {
				return this.actionModel.name;
			}
			return ' ';
		},
		actionDataIndex() {
			return this.$parent.actionDataIndex;
		},
		actionParam() {
			return this.actionModel.param || {};
		},
		enableStorage() {
			return this.$parent.enableStorage;
		},
		storageData() {
			return this.$parent.storageData;
		},
	},
	created() {
		this.$owner = this.$parent.$owner;
		this.$actionPanel = this.$parent;
	},
	methods: {
		baseLoad() {},
		load() {},
		close() {
			this.clearStorage();
			this.modal = false;
		},
		storageClose() {
			this.modal = false;
		},
		clearStorage() {
			return this.$parent.clearStorage();
		},
		modelParam(...arg) {
			return this.$parent.modelParam(...arg);
		},
		//固定提交模式，通过submitData定义提交数据,path.submit定义提交路径
		submitData() {
			return null;
		},
		submitParam() {
			return {};
		},
		submitPath() {
			return this.path.submit;
		},
		//提交完成后调用
		actionAfter() {},
		actionSubmit() {
			$.link(this.path.submit || this.submitPath(), this.submitData(), {
				method: this.submitMethod,
				param: this.submitParam(),
			}).then(() => {
				this.$parent.actionSuccess();
				this.close();
				this.actionAfter();
			});
		},
	},
	components: {
		Modal,
	},
};
</script>
<style lang="less">

</style>
